package com.ruoyi.bath.request.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bath.request.domain.Request;
import com.ruoyi.bath.request.service.IRequestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 申请信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-06
 */
@RestController
@RequestMapping("/bath/request")
public class RequestController extends BaseController
{
    @Autowired
    private IRequestService requestService;

    /**
     * 查询申请信息列表
     */
   // @PreAuthorize("@ss.hasPermi('bath:request:list')")
    @GetMapping("/list")
    public TableDataInfo list( Request request)
    {
        startPage();
        List<Request> list = requestService.selectRequestList(request);
        return getDataTable(list);
    }

    /**
     * 导出申请信息列表
     */
    @PreAuthorize("@ss.hasPermi('bath:request:export')")
    @Log(title = "申请信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Request request)
    {
        List<Request> list = requestService.selectRequestList(request);
        ExcelUtil<Request> util = new ExcelUtil<Request>(Request.class);
        return util.exportExcel(list, "申请信息数据");
    }

    /**
     * 获取申请信息详细信息
     */
   // @PreAuthorize("@ss.hasPermi('bath:request:query')")
    @GetMapping(value = "/lists")
    public List<Request> getInfo(Request request)
    {
        return (List<Request>) requestService.selectRequest(request);
    }

    /**
     * 新增申请信息
     */
    @PreAuthorize("@ss.hasPermi('bath:request:add')")
    @Log(title = "申请信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Request request)
    {
        return toAjax(requestService.insertRequest(request));
    }

    /**
     * 修改申请信息
     */
    @PreAuthorize("@ss.hasPermi('bath:request:edit')")
    @Log(title = "申请信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Request request)
    {
        return toAjax(requestService.updateRequest(request));
    }

    /**
     * 删除申请信息
     */
   // @PreAuthorize("@ss.hasPermi('bath:request:remove')")
    @Log(title = "申请信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)


    {
        return toAjax(requestService.deleteRequestByIds(ids));
    }

    @PostMapping("/time")
    public AjaxResult addRequestTime(Request request){

        requestService.insertaddRequestTime(request);

        return AjaxResult.success(request);
    }
    //根据预约传来的对象删除
    @PostMapping("/deletemsg/{id}")
    public AjaxResult deletemsg(@PathVariable Integer id){

        requestService.deletemsg(id);

       return AjaxResult.success();
    }
}
